import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_my_web/bean/GetHomeDataResponse.dart';
import 'package:flutter_my_web/bean/response/get_text_response.dart';
import 'package:flutter_my_web/utils/JumpActionUtils.dart';
import 'package:flutter_lib/utils/LogUtils.dart';
import 'package:flutter_lib/utils/DpUtils.dart';
import 'package:flutter_my_web/widget/TextWidget.dart';
import 'package:get/get.dart' as Getx;
import 'package:get/get_state_manager/src/rx_flutter/rx_obx_widget.dart';

class HomeListItemView extends StatelessWidget {
  var isHover = false.obs;
  var _bean = TextResponse();

  HomeListItemView(TextResponse _bean) {
    this._bean = _bean;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 200.0.hDp,
      margin: EdgeInsets.only(top: 10.0.hDp, left: 10.0.wDp, right: 10.0.wDp),
      child: FractionallySizedBox(
        widthFactor: 0.7,
        child: Material(
          borderRadius: BorderRadius.all(Radius.circular(6)),
          child: InkWell(
            hoverColor: Color.fromARGB(66, 66, 185, 131),
            onTap: () {
              JumpActionUtils.jumpAction(
                  _bean.type ?? "", _bean.id ?? "");
            },
            onHover: (value) {
              isHover.value = value;
            },
            child: Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                Expanded(
                  child: Obx(() => Container(
                        // color: isHover.value
                        //     ? Colors.transparent
                        //     : Colors.transparent,
                        color: Colors.black,
                        // child: Image.network(_bean.url,fit: s.value==1?BoxFit.fitHeight :BoxFit.fitWidth ),
                        child: Image.network(_bean.coverUrl ?? "",
                            fit: isHover.value ? BoxFit.cover : BoxFit.fill),
                      )),
                ),
                Expanded(
                    child: Container(
                  padding: EdgeInsets.all(10.0.wDp),
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                        children: [
                          Icon(
                            Icons.access_time,
                          ),
                          Container(
                            width: 5.0.wDp,
                          ),
                          SimpleText(
                            _bean.title ?? "",
                            fontSize: 14.sp,
                            color: Color(0x88888888),
                          ),
                        ],
                      ),
                      Container(
                        height: 5.0.hDp,
                      ),
                      SimpleText(
                        _bean.title ?? "",
                        fontSize: 23.sp,
                        color: Color(0xff273849),
                        fontWeight: FontWeight.bold,
                      ),
                      Container(
                        height: 10.0.hDp,
                      ),
                      (_bean.tagList().length > 0)
                          ? Wrap(
                              direction: Axis.horizontal,
                              children: _bean
                                  .tagList()
                                  .map((e) => _TagWidget(e))
                                  .toList(),
                            )
                          : Container(),
                      Container(
                        height: 10.0.hDp,
                      ),
                      Text(
                        _bean.content ?? "",
                        style: TextStyle(
                          color: Color(0x77000066),
                          fontSize: 16.sp,
                        ),
                        maxLines: 5,
                        softWrap: true,
                        overflow: TextOverflow.ellipsis,
                      ),
                      Expanded(child: Container()),
                      Align(
                          alignment: Alignment.centerRight,
                          child: Icon(Icons.more)),
                    ],
                  ),
                ))
              ],
            ),
          ),
        ),
      ),
    );
  }
}

class _TagWidget extends StatelessWidget {
  String? _bean;

  _TagWidget(this._bean);

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisSize: MainAxisSize.min,
      children: [
        Icon(
          Icons.ac_unit,
          size: 16.0.wDp,
        ),
        Container(
          width: 5.0.wDp,
        ),
        SimpleText(
          _bean ?? "",
          fontSize: 16.sp,
          color: Color(0xff8a8a8a),
        ),
        Container(
          width: 5.0.wDp,
        ),
      ],
    );
  }
}
